home *** CD-ROM | disk | FTP | other *** search
/ Gigarom 1 / Gigarom Macintosh Archives (Quantum Leap)(CDRM1080320)(1993).iso / FILES / BBS / MUBBS / MUBBS etc.cpt / Module Source / Menu Module code / Menu Module.c < prev    next >
Text File  |  1991-11-19  |  6KB  |  206 lines

  1. /* *********************************************************************************
  2.      
  3.       MODULE:        Menu Module
  4.       
  5.      DESCRIPTION:    This menu module is a simple module for MUBBS, the Multi-User
  6.                      Bulliten Board System Software.
  7.                      
  8.      AUTHOR:        Noam Freedman
  9.      
  10.      Copyright © 1990 by Noam Freedman, All Rights Reserved.
  11.      
  12.      Revision History:
  13.      ============================================================
  14.      9/23/91 - Started programming the module.
  15.      9/26/91 - Finished the basic module.
  16.      9/30/91 - Added some bug fixes.
  17.      10/3/91 - Finally fixed the menu info loader.
  18.      10/6/91 - Modified by N Hawthorn for release
  19.      ============================================================
  20.      
  21.      COMMENTS:    You MUST RENAME this module for each DIFFERENT menu you
  22.                  want.
  23.                  Module names are never over 26 characters !!
  24.  
  25.    ********************************************************************************
  26.    
  27.    The code to this Module is being released for the SOLE purpose to be a tutorial
  28.    for programmers trying to program modules for MUBBS.  Portions of this code may be
  29.    used for non-commercial, no-cost-to-use modules (ie: You can't charge for any
  30.    module using any part of this code....even shareware) without the consent of
  31.    the author.  Any module using this code must give credit to the author,
  32.    Noam Freedman.
  33.    
  34.    ******************************************************************************** */
  35.  
  36. #define INMAIN
  37.  
  38. #include     <SetUpA4.h>
  39. #include    "MUBBS Module.h"
  40.  
  41. /* my globals for this module */
  42.  
  43.  
  44.  
  45. pascal void main (mode1,G1,P1)
  46.        int mode1;
  47.        struct GS *G1;
  48.        Ptr *P1; /* we ignore "P" in this module */
  49. {
  50. Handle temph;
  51. float version = 0.5; /* what version of MUBBS you are compatable with IE: .5 and above */
  52. RememberA0(); SetUpA4(); /* This sets up the A4 register to access our globals */
  53. asm { _RecoverHandle }; asm {move.l a0,temph}; HLock(temph); /* locks our module, do this ! */
  54.  
  55. G=G1; /* This MUST be the first thing you do in main only, it sets up the struct globals */
  56. mode[u]=mode1; /* set up our mode so that you can read it anywhere */
  57.  
  58. switch (mode[u]) { /* any un-handled modes return error from this module */
  59.     case 2:
  60.         domenu();
  61.         G->moduleresult=0;
  62.         break;
  63.     case 98:
  64.         versionck(version); /* just return after this call, don't modify anything */
  65.         break;        
  66.     case 0:
  67.         strcpy (G->programmer,"Noam Freedman"); /* show the programmer's name up to 20 chars*/
  68.         G->moduleresult=0; /* this was also a init call if we need close call put 99 here */
  69.         break;
  70.     default:
  71.         G->moduleresult=1; /* return bad code */
  72.     };
  73.  
  74. HUnlock(temph); /* unlocks this module, do this ! */
  75. RestoreA4(); /* call this when you are all done */
  76. }
  77.  
  78.  
  79. /* DISPLAY THE TEXT, IF ANY, FOR THE MENU */
  80.  
  81.  
  82. displaymenu()
  83. {
  84. char tempstring[100];
  85. /* Generate the filename */
  86. strcpy(tempstring,":menus:");  
  87. strcat(tempstring,G->modulename[u]);
  88. if (G->language[u] == 1)
  89.     strcat(tempstring,".ansi");
  90. else
  91.     strcat(tempstring,".txt");
  92.  
  93. /* Display the textfile */
  94. G->okcancel[u]=TRUE;
  95. G->nocheck[u]=FALSE; /* check for controls */
  96. G->cancel[u]=FALSE;
  97. sendtext(tempstring);
  98. }
  99.  
  100. checktime(warned) /* check if they are out of time yet */
  101. int warned;
  102. {
  103.  
  104. if(G->timeon[u] >= G->timeallowed[u]) {
  105.     send("]]YOUR TIME HAS EXPIRED, PLEASE CALL BACK TOMMOROW..]");
  106.     G->online[u]=FALSE; /* log them off now ! */
  107.     return TRUE;
  108.     }
  109. if(!warned && (G->timeon[u]+5) >= G->timeallowed[u]) {
  110.     send("]LOGOFF WARNING, YOU HAVE 5 MINUTES OF TIME LEFT !]");
  111.     return TRUE;
  112.     }
  113. return FALSE;
  114. }
  115.  
  116.  
  117. /* ASKUSER ASKS THE USER FOR INPUT THEN LAUNCHES THE CORRECT MODULE */
  118.  
  119. domenu()
  120. {
  121. int i,a,num,warned;
  122. char ch;
  123. FILE *stream; /* you MUST define this here so that other nodes don't get messed up */
  124. char tempstring[100];
  125. char m_realnames[21][30],    /* up to 20 menu selections are allowed */
  126.      modulesc[21];           /* in MUBBS we don't use many selections on */
  127.                                     /* one menu anyway */
  128.  
  129. if (!G->online[u]) goto byebye; /* do this check so we can log out if hang up */
  130.  
  131. /* Generate the filename */
  132. strcpy(tempstring,":menus:");
  133. strcat(tempstring,G->modulename[u]);
  134. strcat(tempstring,".info");
  135. /* LOAD IN THE INFORMATION FOR THE MENU */
  136.  
  137. i = 0;
  138.  
  139. /* Open the file */
  140. if ((stream = fopen(tempstring, "r")) == NULL) {
  141.     send("]FILE ERROR cannot open %s ", /*its a %d ,errno,*/  tempstring);
  142.     return;
  143.     }
  144. else    /* If no error, read from the file */
  145.     {                
  146.     a = 0;
  147.     while (a == 0){
  148.             if(fscanf(stream,"%c\n",&modulesc[i]) != EOF) {  /* Read and check for EOF */
  149.                 if (fgets(m_realnames[i],30,stream) != NULL)  {  /* Read and check for EOF */
  150.                     remlf(m_realnames[i]); /* take out line feed */
  151.                     i++;
  152.                     if (i >= 20) a = 1;        
  153.                 }
  154.             }
  155.             else {
  156.                 a = 1;
  157.                 }
  158.         }
  159.     fclose(stream);
  160.     }
  161.  
  162. num=i;       /*   Loads in the choice of modules from a text file      */
  163. warned=FALSE; /* they havent been warned yet... */
  164.  
  165. while (TRUE)
  166.     {
  167.     if (!G->online[u]) goto byebye; /* do this check so we can log out if hang up */
  168.     loguser(G->modulename[u]); /* this tells where you are for remote sysop, or writes to log file */
  169.     print("C> Line %d %s, at: %s\n",(u+1),G->username[u],G->modulename[u]);
  170.     displaymenu();    /*   Displays the text, for the menu                      */
  171.     if (!G->online[u]) goto byebye; /* do this check so we can log out if hang up */
  172.     warned=checktime(warned);
  173.     if (!G->online[u]) goto byebye; /* do this check so we can log out if hang up */
  174.  
  175.     if (!(cmd1(""))) goto byebye; /* timeout ? */
  176.     ch = G->input[u];
  177.  
  178.     /* Check to see if the user typed a valid key, and if so, launch the module */
  179.     for (i = 0;i<num;i++)
  180.         if (ch == modulesc[i])
  181.             {
  182.             send (G->CR[u]);  /* don't do: send ("]"), you waste data area space */
  183.             if (strcmp(m_realnames[i],"quit") == 0) return;   /* If the user hit Quit, then just return */
  184.             if (strcmp(m_realnames[i],"logoff") == 0) goto byebye; /* cause a logoff */
  185.             module(2,m_realnames[i],0L);
  186.             i = 1 + num;
  187.             }
  188.     }
  189.  
  190. byebye:
  191. G->online[u]=FALSE; /* show we timed out */
  192. }
  193.  
  194. remlf(string)
  195. char *string;
  196. {
  197. int temp,b;
  198. b = strlen(string);
  199. for (temp=0; temp<= b; temp++) 
  200.     {
  201.     if (string[temp] == 10)
  202.         string[temp] = 0;
  203.     }
  204.  
  205. }
  206.